home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 34 / Mac Magazin and MacEasy Magazine CD - Issue 34.iso / Grafik & Text / Alpha ƒ / Tcl / Modes / latexComm.tcl < prev    next >
Text File  |  1996-09-22  |  19KB  |  672 lines

  1. #############################################################################
  2. #############################################################################
  3. #
  4. # latexComm.tcl (called from latex.tcl)
  5. #
  6. #############################################################################
  7. #
  8. # Author:  Tom Scavo <trscavo@syr.edu>
  9. #
  10. #############################################################################
  11. #############################################################################
  12.  
  13. #--------------------------------------------------------------------------
  14. # TeX applications
  15. #--------------------------------------------------------------------------
  16.  
  17. # Application *names* aren't needed any more!
  18.  
  19. # In the following scripts, $quotedSig and $filename are the application 
  20. # signature and the name of the file to be typeset, respectively.  (See
  21. # proc 'evalTeXScript' below.)
  22.  
  23. # OzTeX:
  24. # set texAppName(OzTeX) {*OzTeX*}
  25. set texAppSig(OzTeX) {OTEX}
  26. set texAppScripts(OzTeX) {
  27.     {sendOpenEvent noReply $quotedSig $filename}
  28. }
  29.     
  30. # Textures:
  31. # set texAppName(Textures) {*Textures*}
  32. set texAppSig(Textures) {*TEX}
  33. # This is the old Textures typesetting script:
  34. # set texAppScripts(Textures) {{dosc -c $quotedSig -f $filename -r}}
  35. set texAppScripts(Textures) {
  36.     {global TeXconnections} 
  37.     {set TeXjob ""} 
  38.     {
  39.         foreach entry $TeXconnections {
  40.             if { [car $entry] == $filename } {
  41.                 set TeXjob [cadr $entry]
  42.                 break
  43.             }
  44.         }
  45.     } 
  46.     {
  47.         if { $TeXjob == "" } {
  48.             set TeXjob [AEBuild -r $quotedSig BSRs Begi]
  49.             set TeXjob [string trim [string range $TeXjob 15 end] {\{\}\"}]
  50.             lappend TeXconnections [list $filename $TeXjob]
  51.         }
  52.     } 
  53.     {AEBuild -t 1200 $quotedSig BSRs Typs "----" [makeAlis $filename] fmat {"LaTeX"} Jobi $TeXjob} 
  54. }
  55.  
  56. # CMacTeX:
  57. # set texAppName(CMacTeX) {*tex}
  58. set texAppSig(CMacTeX) {*XeT}
  59. set texAppScripts(CMacTeX) {
  60.     {dosc -c $quotedSig -k 'aevt' -e 'odoc' -r -f $filename}
  61. }
  62.     
  63. # DirectTeX:
  64. # set texAppName(DirectTeX) {MPW*}
  65. set texAppSig(DirectTeX) {MPS*}
  66. set texAppScripts(DirectTeX) {
  67.     {set script "Begin; ChangeTeXProject '$filename' -check -confirm || Exit 0; \
  68.                     Execute \"{dt_TeXProject}\"; TeXMenu -tex -formats; \
  69.                   End ∑ Dev:Null; RunSession 1 ∑ Dev:Null"} 
  70.     {dosc -r -c $quotedSig -s $script} 
  71. }
  72.  
  73. # DirectTeX Pro:
  74. # set texAppName(DirectTeXPro) {DirectTeX*}
  75. set texAppSig(DirectTeXPro) {TeX+}
  76. set texAppScripts(DirectTeXPro) {
  77.     {dosc -c $quotedSig -s \
  78.         "if \$dt_TeXFormat = \'\' \"set dt_TeXFormat -x \$dt_DefaultFormat\""} 
  79.     {dosc -c $quotedSig -s \
  80.         "ProjectMgr -t \$dt_TeXFormat \"$filename\"; MenuCommand 1 4"} 
  81. }
  82.  
  83. #--------------------------------------------------------------------------
  84. # DVI viewers
  85. #--------------------------------------------------------------------------
  86.  
  87. # OzTeX:
  88. # set viewDVIAppName(OzTeX) $texAppName(OzTeX)
  89. set viewDVIAppSig(OzTeX) $texAppSig(OzTeX)
  90. set viewDVIAppScripts(OzTeX) {
  91.     {sendOpenEvent noReply $quotedSig $filename}
  92. }
  93.     
  94. # Textures:
  95. # set viewDVIAppName(Textures) $texAppName(Textures)
  96. set viewDVIAppSig(Textures) $texAppSig(Textures)
  97. set viewDVIAppScripts(Textures) {
  98.     {AEBuild $quotedSig aevt odoc "----" [makeAlis $filename]}
  99. }
  100.     
  101. # CMacTeX:
  102. # set viewDVIAppName(CMacTeX) dvipreview
  103. set viewDVIAppSig(CMacTeX) {PIVD}
  104. set viewDVIAppScripts(CMacTeX) {
  105.     {dosc -c $quotedSig -k 'aevt' -e 'odoc' -r -f $filename}
  106. }
  107.     
  108. # DirectTeX Pro:
  109. # set viewDVIAppName(DirectTeXPro) $texAppName(DirectTeXPro)
  110. set viewDVIAppSig(DirectTeXPro) $texAppSig(DirectTeXPro)
  111. # set viewDVIAppScripts(DirectTeXPro) {
  112. #     {dosc -c $quotedSig -s \
  113. #         "ProjectMgr -t LaTeX \"$filename\"; SelectApp; MenuCommand 1 8"}
  114. # }
  115. set viewDVIAppScripts(DirectTeXPro) {
  116.     {dosc -c $quotedSig -s "ProjectMgr -t \$dt_TeXFormat    \"[lindex    [winNames -f] 0]\"; MenuCommand 1 8"}
  117. }
  118.  
  119. #--------------------------------------------------------------------------
  120. # DVI print drivers
  121. #--------------------------------------------------------------------------
  122.  
  123. # OzTeX:
  124. # set printDVIAppName(OzTeX) $texAppName(OzTeX)
  125. set printDVIAppSig(OzTeX) $texAppSig(OzTeX)
  126. set printDVIAppScripts(OzTeX) {
  127.     {dosc -c $quotedSig -k 'aevt' -e 'pdoc' -r -f $filename}
  128. }
  129.     
  130. # Textures:
  131. # set printDVIAppName(Textures) $texAppName(Textures)
  132. set printDVIAppSig(Textures) $texAppSig(Textures)
  133. set printDVIAppScripts(Textures) {
  134.     {AEBuild $quotedSig aevt pdoc "----" [makeAlis $filename]}
  135. }
  136. # set printDVIAppScripts(Textures) \
  137. #     {{dosc -c $quotedSig -k 'aevt' -e 'pdoc' -r -f $filename}}
  138.     
  139. # CMacTeX:
  140. # set printDVIAppName(CMacTeX) printdvi
  141. set printDVIAppSig(CMacTeX) {CMT8}
  142. set printDVIAppScripts(CMacTeX) {
  143.     {dosc -c $quotedSig -k 'aevt' -e 'pdoc' -r -f $filename}
  144. }
  145.     
  146. # DirectTeX Pro:
  147. # set printDVIAppName(DirectTeXPro) $texAppName(DirectTeXPro)
  148. set printDVIAppSig(DirectTeXPro) $texAppSig(DirectTeXPro)
  149. set printDVIAppScripts(DirectTeXPro) {
  150.     {dosc -c $quotedSig -s \
  151.         "ProjectMgr -t \$dt_TeXFormat    \"[lindex    [winNames -f] 0]\"; MenuCommand 1 9"}
  152. }
  153.  
  154. #--------------------------------------------------------------------------
  155. # DVI-to-PS filters
  156. #--------------------------------------------------------------------------
  157.  
  158. # OzTeX:
  159. # set dvipsAppName(OzTeX) OzDVIPS
  160. set dvipsAppSig(OzTeX) {OzDP}
  161. set dvipsAppScripts(OzTeX) {
  162.     {sendOpenEvent noReply $quotedSig $filename}
  163. }
  164.     
  165. # CMacTeX:
  166. # set dvipsAppName(CMacTeX) dvips
  167. set dvipsAppSig(CMacTeX) {CMT1}
  168. set dvipsAppScripts(CMacTeX) {
  169.     {dosc -c $quotedSig -k 'aevt' -e 'odoc' -t 600 -f $filename}
  170. }
  171.     
  172. # DirectTeX Pro:
  173. # set dvipsAppName(DirectTeXPro) $texAppName(DirectTeXPro)
  174. set dvipsAppSig(DirectTeXPro) $texAppSig(DirectTeXPro)
  175. set dvipsAppScripts(DirectTeXPro) {
  176.     {dosc -c $quotedSig -s \
  177.         "ProjectMgr -t \$dt_TeXFormat    \"[lindex    [winNames -f] 0]\"; \
  178.         directory \$dt_TeXProjectDir > CurrDirectory; dvips \$dt_TeXProjectName"}
  179. }
  180.  
  181. #--------------------------------------------------------------------------
  182. # PS viewers
  183. #--------------------------------------------------------------------------
  184.  
  185. # Mac GhostScript Viewer:
  186. # set viewPSAppName(MacGS) {Mac GS*}
  187. set viewPSAppSig(MacGS) {gsVR}
  188. set viewPSAppScripts(MacGS) {
  189.     {dosc -c $quotedSig -k 'aevt' -e 'odoc' -r -f $filename}
  190. }
  191.     
  192. # CMacTeX:
  193. # set viewPSAppName(CMacTeX) viewps
  194. set viewPSAppSig(CMacTeX) {CMT5}
  195. set viewPSAppScripts(CMacTeX) {
  196.     {dosc -c $quotedSig -k 'aevt' -e 'odoc' -r -f $filename}
  197. }
  198.  
  199. #--------------------------------------------------------------------------
  200. # PS print drivers
  201. #--------------------------------------------------------------------------
  202.  
  203. # CMacTeX: 
  204. # set printPSAppName(CMacTeX) printps
  205. set printPSAppSig(CMacTeX) {PSP*}
  206. set printPSAppScripts(CMacTeX) {
  207.     {dosc -c $quotedSig -k 'aevt' -e 'odoc' -r -f $filename}
  208. }
  209.     
  210. # DirectTeX Pro:
  211. # set printPSAppName(DirectTeXPro) $texAppName(DirectTeXPro)
  212. set printPSAppSig(DirectTeXPro) $texAppSig(DirectTeXPro)
  213. # set printPSAppScripts(DirectTeXPro) {
  214. #     {dosc -c $quotedSig -s "SelectApp; dvips \$dt_TeXProjectName; \
  215. #                              download \$dt_TeXProjectName.ps"}
  216. # }
  217. set printPSAppScripts(DirectTeXPro) {
  218.     {dosc -c $quotedSig -s \
  219.         "ProjectMgr -t \$dt_TeXFormat    \"[lindex    [winNames -f] 0]\"; \
  220.         directory \$dt_TeXProjectDir > CurrDirectory; download \$dt_TeXProjectName.ps"}
  221. }
  222.  
  223. # Drop•PS
  224. # set printPSAppName(DropPS) {Drop•PS}
  225. set printPSAppSig(DropPS) {D•PS}
  226. set printPSAppScripts(DropPS) {
  227.     {dosc -c $quotedSig -k 'aevt' -e 'odoc' -r -f $filename}
  228. }
  229.  
  230. #--------------------------------------------------------------------------
  231. # BibTeX apps
  232. #--------------------------------------------------------------------------
  233.  
  234. # CMacTeX:
  235. # set bibtexAppName(CMacTeX) {*bibtex}
  236. set bibtexAppSig(CMacTeX) {CMTu}
  237. set bibtexAppScripts(CMacTeX) {
  238.     {sendOpenEvent noReply $quotedSig $filename}
  239. }
  240.     
  241. # DirectTeX Pro:
  242. # set bibtexAppSig(DirectTeXPro) $texAppSig(DirectTeXPro)
  243. set bibtexAppScripts(DirectTeXPro) {
  244.     {dosc -c $quotedSig -s \
  245.         "ProjectMgr -t \$dt_TeXFormat    \"[lindex    [winNames -f] 0]\"; MenuCommand 1 5"}
  246. }
  247.  
  248. # Vince Darley's BibTeX:
  249. # set bibtexAppName(BibTeX) {BibTeX*}
  250. set bibtexAppSig(BibTeX) {Vbib}
  251. set bibtexAppScripts(BibTeX) {
  252.     {sendOpenEvent noReply $quotedSig $filename}
  253. }
  254.  
  255. #--------------------------------------------------------------------------
  256. # MakeIndex apps
  257. #--------------------------------------------------------------------------
  258.  
  259. # CMacTeX:
  260. # set makeindexAppName(CMacTeX) {[Mm]ake[Ii]ndex}
  261. set makeindexAppSig(CMacTeX) {CMTt}
  262. set makeindexAppScripts(CMacTeX) {
  263.     {sendOpenEvent noReply $quotedSig $filename}
  264. }
  265.     
  266. # DirectTeX Pro:
  267. # set makeindexAppName(DirectTeXPro) $texAppName(DirectTeXPro)
  268. set makeindexAppSig(DirectTeXPro) $texAppSig(DirectTeXPro)
  269. # set makeindexAppScripts(DirectTeXPro) {
  270. #     {dosc -c $quotedSig -s \
  271. #         "ProjectMgr -t LaTeX \"$filename\"; SelectApp; MenuCommand 1 6"}
  272. # }
  273. set makeindexAppScripts(DirectTeXPro) {
  274.     {dosc -c $quotedSig -s \
  275.         "ProjectMgr -t \$dt_TeXFormat    \"[lindex    [winNames -f] 0]\"; MenuCommand 1 6"}
  276. }
  277.  
  278. # Rick Zaccone's MakeIndex:
  279. # set makeindexAppName(MakeIndex) {MakeIndex*}
  280. set makeindexAppSig(MakeIndex) {RZMI}
  281. set makeindexAppScripts(MakeIndex) {
  282.     {sendOpenEvent noReply $quotedSig $filename}
  283. }
  284.  
  285. #--------------------------------------------------------------------------
  286. # Typeset submenu commands
  287. #--------------------------------------------------------------------------
  288.  
  289. proc typeset {} {
  290.     # Is there a window open?
  291.     set currentWin [lindex [winNames -f] 0]
  292.     if { $currentWin == "" } {
  293.         typesetFile ""
  294.         return
  295.     }
  296.     # Is the current window part of TeX fileset?
  297.     set fset [isWindowInFileset $currentWin "tex"]
  298.     if { $fset != "" } {
  299.         if [dirtyFileset $fset] {
  300.             switch [askyesno -c "Save current TeX fileset?"] {
  301.                 "yes" {saveEntireFileset $fset}
  302.                 "no" {
  303.                      # do nothing
  304.                 }
  305.                 "cancel" {return}
  306.             }
  307.         }
  308.         typesetFile [texFilesetBaseName $fset]
  309.         return
  310.     }
  311.     # Is the window untitled or dirty?
  312.     global PREFS
  313.     set currentDoc [file tail $currentWin]
  314.     if { [set num [winUntitled]] } {
  315.         switch [askyesno -c "Save \"$currentDoc\"?"] {
  316.             "yes" {
  317.                 if {[catch {set currentWin [saveAs "Untitled$num\.tex"]}]} then {return}
  318.             }
  319.             "no" {
  320.                 set tmpFilename "Untitled$num\.tex"
  321.                 set text [getText 0 [maxPos]]
  322.                 if { [file exists "$PREFS:tmp"] == 0 } { mkdir "$PREFS:tmp" }
  323.                 set newDoc "$PREFS:tmp:$tmpFilename"
  324.                 writeFile $newDoc $text 1
  325.                 set currentWin $newDoc
  326.             }
  327.             "cancel" {return}
  328.         }
  329.     } elseif { [winDirty] } {
  330.         switch [askyesno -c "Save \"$currentDoc\"?"] {
  331.             "yes" {save}
  332.             "no" {
  333.                 set text [getText 0 [maxPos]]
  334.                 if { [file exists "$PREFS:tmp"] == 0 } { mkdir "$PREFS:tmp" }
  335.                 set newDoc "$PREFS:tmp:temp-$currentDoc"
  336.                 writeFile $newDoc $text 1
  337.                 set currentWin $newDoc
  338.             }
  339.             "cancel" {return}
  340.         }
  341.     }
  342.     # Is the current window TeX-able?
  343.     set ext [file extension $currentWin]
  344.     if { [lsearch -exact {.tex .ltx .dtx .ins} $ext] < 0 } {
  345.         typesetFile ""
  346.         return
  347.     }
  348.     # Strip off trailing garbage (if any) and typeset:
  349.     regexp {(.*) <[0-9]+>} $currentWin dummy currentWin
  350.     typesetFile $currentWin
  351. }
  352.  
  353. proc typesetSelection {} {
  354.     global PREFS
  355.     if { [isSelection] } then { 
  356.         watchCursor
  357.         message "processing selection…"
  358.         set currentWin [lindex [winNames -f] 0]
  359.         # Is the current window part of TeX fileset?
  360.         set fset [isWindowInFileset $currentWin "tex"]
  361.         if { $fset == "" } {
  362.             set pos1 [getPos]
  363.             if { [isInDocument] } then {
  364.                 set pos2 [selEnd]
  365.                 if { [isInDocument] } then {
  366.                     # fall through
  367.                 } else {
  368.                     beep
  369.                     set msg "Selection not in document environment.  Continue?"
  370.                     if { [askyesno $msg] == "no" } then { return }
  371.                 }
  372.             } else {
  373.                 beep
  374.                 set msg "Selection not in document environment.  Continue?"
  375.                 if { [askyesno $msg] == "no" } then { return }
  376.                 set pos2 [selEnd]
  377.             }
  378.             set body "\r[getText $pos1 $pos2]\r"
  379.             set searchText [getText 0 [maxPos]]
  380.         } else {
  381.             set body "\r[getSelect]\r"
  382.             # Will not handle a base file that is open and dirty:
  383.             set searchText [buildFilecontents [texFilesetBaseName $fset]]
  384.         }
  385.         message "building temporary document…"
  386.         set pattern {(\\documentclass.*)\\begin\{document\}}
  387.         if { ![regexp $pattern $searchText dummy preamble] } then {
  388.             set preamble "\\documentclass\{article\}\r"
  389.         }
  390.         set rootFile [file rootname $currentWin]
  391.         set tempFile "temp-[file tail $rootFile]"
  392.         set auxFile $rootFile.aux
  393.         if { [file exists $auxFile] } {
  394.             set latexDoc [buildFilecontents $auxFile $tempFile.aux]
  395.         } else {
  396.             set latexDoc {}
  397.         }
  398.         append latexDoc $preamble [buildEnvironment "document" "" $body "\r"]
  399.         set currentDir [file dirname $currentWin]
  400.         set latexDoc [texResolveAll $latexDoc $currentDir]
  401.         if { [file exists "$PREFS:tmp"] == 0 } { mkdir "$PREFS:tmp" }
  402.         set newFile "$PREFS:tmp:$tempFile.tex"
  403.         writeFile $newFile $latexDoc 1
  404.         typesetFile $newFile
  405.     } else {
  406.         beep
  407.         message "no selection"
  408.     }
  409. }
  410.  
  411. proc typesetClipboard {} {
  412.     global PREFS
  413.     set body "\r[getScrap]\r"
  414.     set pat1 {\\begin\{document\}.*\\end\{document\}}
  415.     set pat2 {\\documentclass}
  416.     set preamble "\\documentclass\{article\}\r"
  417.     # Check to see if there's a document environment:
  418.     if {![regexp $pat1 $body]} then {
  419.         append text $preamble [buildEnvironment "document" "" $body "\r"]
  420.     } else {
  421.         # Check to see if there's a \documentclass command:
  422.         if {![regexp $pat2 $body]} then {
  423.             append text $preamble $body
  424.         } else {
  425.             set text $body
  426.         }
  427.     }
  428.     if { [file exists "$PREFS:tmp"] == 0 } { mkdir "$PREFS:tmp" }
  429.     set newFile "$PREFS:tmp:temp-noname\.tex"
  430.     writeFile $newFile $text 1
  431.     set currentWin $newFile
  432.     typesetFile $currentWin
  433. }
  434.  
  435. # Typeset $filename, but perform no error-checking
  436. #
  437. proc typesetFile {filename} {
  438.     if { $filename == "" } {
  439.         set filename [getfile "Choose a file to typeset:"]
  440.     }
  441.     global TeXmodeVars
  442.     set prompt {TeX app}
  443.     set flag $TeXmodeVars(runTeXInBack)
  444.     evalTeXScript tex $prompt $filename $flag
  445. }
  446.  
  447. # Apply $op to a file with extension $ext.  (See latexMenu.tcl for
  448. # many examples.)  If 'forcecurrent == 1', use the current window 
  449. # even if it belongs to a TeX fileset.
  450. #
  451. proc doTypesetCommand {op ext {forcecurrent 0}} {
  452.     if { [set filename [findAuxiliaryFile $ext $forcecurrent]] != "" } {
  453.         if { $op == "open" } { 
  454.             edit -r -m -w $filename 
  455.         } else {
  456.             $op${ext}File $filename
  457.         }
  458.     } else {
  459.         beep
  460.         alertnote "No $ext file found!"
  461.     }
  462. }
  463.  
  464. proc viewDVIFile {filename} {
  465.     set prompt {DVI viewer}
  466.     evalTeXScript viewDVI $prompt $filename
  467. }
  468.  
  469. proc printDVIFile {filename} {
  470.     set prompt {DVI print driver}
  471.     evalTeXScript printDVI $prompt $filename
  472. }
  473.  
  474. proc dvipsDVIFile {filename} {
  475.     set prompt {DVI-to-PS filter}
  476.     evalTeXScript dvips $prompt $filename
  477. }
  478.  
  479. proc viewPSFile {filename} {
  480.     set prompt {PS viewer}
  481.     evalTeXScript viewPS $prompt $filename
  482. }
  483.  
  484. proc printPSFile {filename} {
  485.     set prompt {PS print driver}
  486.     evalTeXScript printPS $prompt $filename
  487. }
  488.  
  489. proc bibtexAUXFile {filename} {
  490.     set prompt {BibTeX app}
  491.     evalTeXScript bibtex $prompt $filename
  492. }
  493.  
  494. proc makeindexIDXFile {filename} {
  495.     set prompt {MakeIndex app}
  496.     evalTeXScript makeindex $prompt $filename
  497. }
  498.  
  499. proc evalTeXScript {op prompt filename {runAppInBackground 0}} {
  500.     global ${op}Sig ${op}AppSig ${op}AppScripts
  501.     
  502.     set supportedApps [array names ${op}AppSig]
  503.     foreach app $supportedApps { lappend sigs [set ${op}AppSig($app)] }
  504.     set longPrompt "Please locate a $prompt."
  505.     if { [catch {launchBackApplSigs $sigs ${op}Sig $longPrompt} appname] } {
  506.         error "bug in 'launchBackApplSigs'"
  507.     }
  508.     set sig [set ${op}Sig]
  509.     set quotedSig "'[string trim $sig {'}]'"
  510. #     if { $runAppInBackground == 0 } { switchTo [file tail $appname] }
  511.     if { $runAppInBackground == 0 } { switchTo $quotedSig }
  512.     foreach app $supportedApps { 
  513.         if { [set ${op}AppSig($app)] == $sig } {
  514.             foreach script [set ${op}AppScripts($app)] {
  515.                 eval $script
  516.             }
  517.             return
  518.         }
  519.     }
  520.     beep
  521.     alertnote "Sorry, no support for your $prompt."
  522.     return
  523. }
  524.  
  525. # Two bugs in 'getfile' (see "alpha.bugs58"):
  526. proc openAnyTeXFile {} {
  527.     set currentWin [lindex [winNames -f] 0]
  528.     cd [file dirname $currentWin]
  529.     set    filename [getfile ""]
  530.     if { ![string length $filename] } return
  531.     edit -r -m -w $filename
  532. }
  533.  
  534. proc removeAuxiliaryFiles {} {
  535.     set word ""
  536.     set removeSilently 0
  537.     set currentWin [lindex [winNames -f] 0]
  538.     if { $currentWin == "" } { return }
  539.     set currentDir [file dirname $currentWin]
  540.     set extensions {.ps .dvi .log .aux .bbl .idx .ind .glo .gls \
  541.                     .toc .lof .lot .blg .ilg}
  542.     foreach ext $extensions {
  543.         message "Checking for *$ext files…"
  544.         set files [glob -nocomplain "$currentDir:*$ext"]
  545.         foreach file $files {
  546.             set word " more"
  547.             if {$removeSilently} {
  548.                 if {[catch {rm "$currentDir:*$ext"}]} then {
  549.                     alertnote "not all \"*$ext\" files deleted"
  550.                 }
  551.                 break
  552.             } else {
  553.                 message ""
  554.                 set filename [file tail $file]
  555.                 switch [buttonAlert "Remove \"$filename\"?" "yes" "no" {rm ext} {rm all} "cancel"] {
  556.                     "yes" {
  557.                         message "Removing $filename…"
  558.                         if {[catch {removeFile "$currentDir:$filename"}]} then {
  559.                             alertnote "\"$filename\" not deleted"
  560.                         } else {
  561.                             message $filename
  562.                         }
  563.                     }
  564.                     "no" {}
  565.                     "{rm ext}" {
  566.                         if {[catch {rm "$currentDir:*$ext"}]} then {
  567.                             alertnote "not all \"*$ext\" files deleted"
  568.                         }
  569.                         break
  570.                     }
  571.                     "{rm all}" {
  572.                         if {[catch {rm "$currentDir:*$ext"}]} then {
  573.                             alertnote "not all \"*$ext\" files deleted"
  574.                         }
  575.                         set removeSilently 1
  576.                         break
  577.                     }
  578.                     "cancel" {return}
  579.                 }
  580.             }
  581.         }
  582.     }
  583.     message "No$word files found"
  584. }
  585.  
  586. #--------------------------------------------------------------------------
  587. # Utility procs:
  588. #--------------------------------------------------------------------------
  589.  
  590. # Find a LaTeX auxiliary file with extension $ext.  If 'forcecurrent' 
  591. # is true, search the current directory without checking for TeX filesets.
  592. #
  593. proc findAuxiliaryFile {ext {forcecurrent 0}} {
  594.     
  595.     set currentWin [lindex [winNames -f] 0]
  596.     if { $currentWin == "" } { return "" }
  597.     set currentDoc [file tail $currentWin]
  598.  
  599.     if $forcecurrent {
  600.         # pretend there are no TeX filesets:
  601.         set fset ""
  602.     } else {
  603.         set fset [isWindowInFileset $currentWin "tex"]
  604.     }
  605.     
  606.     if { $fset != "" } {
  607.         
  608.         set currentWin [texFilesetBaseName $fset]
  609.         set currentDoc [file tail $currentWin]
  610.         set currentDir [file dirname $currentWin]
  611.         set docBasename [file rootname $currentDoc]
  612.         set lowerExt [string tolower $ext]
  613.         
  614.     } else {
  615.         
  616.         # we do all this if it's not a project:
  617.         set currentDir [file dirname $currentWin]        
  618.         set docBasename [file rootname $currentDoc]
  619.         set lowerExt [string tolower $ext]
  620.         
  621.         # Is the window untitled or dirty?
  622.         global PREFS
  623.         if { [set num [winUntitled]] } {
  624.             set filename $PREFS:tmp:Untitled$num\.$lowerExt
  625.             if { [file exists $filename] } {
  626.                 return $filename
  627.             } else {
  628.                 return ""
  629.             }
  630.         } elseif { [winDirty] } {
  631.             switch [askyesno "Window dirty---continue anyway?"] {
  632.                 "yes" {
  633.                     set filename $PREFS:tmp:temp-$currentDoc\.$lowerExt
  634.                     if { [file exists $filename] } {
  635.                         return $filename
  636.                     } else {
  637.                         # fall through
  638.                     }
  639.                 }
  640.                 "no" {return ""}
  641.             }
  642.         }
  643.     }
  644.     
  645.     # Check the current directory:
  646.     set filename $currentDir:$docBasename\.$lowerExt
  647.     if { [file exists $filename] } {
  648.         return $filename
  649.     } else {
  650.         return ""
  651.     }
  652. }
  653.  
  654. # If the current window is untitled, return its number (i.e., either
  655. # the number 1 or the number  n  in "Untitled <n>"); otherwise, return 0.
  656. proc winUntitled {} {
  657.     set currentWin [lindex [winNames -f] 0]
  658.     if { $currentWin == "" } { return 0 }
  659.     set currentDoc [file tail $currentWin]
  660.     if { [string match $currentWin $currentDoc] } {
  661.         if { [regexp {<(.*)>} $currentDoc dummy num] } {
  662.             return $num
  663.         } else {
  664.             return 1
  665.         }
  666.     } else {
  667.         return 0
  668.     }
  669. }
  670.  
  671.  
  672.